#include<bits/stdc++.h>
using namespace std;
struct car{
	int s,e,v,a;
}c[100005];
int p[100005];
int n,m,L,v,ff;
long long sv(int v0,int a,int dis){
	return v0*v0+2*a*dis;
}
bool f=0;
int test(){
	int ans=0,t;
	long long ve,vf;
	for(int i=1;i<=n;i++){
		if(c[i].s>p[m])continue;
		if(c[i].a==0){
			if(c[i].v>v){
				ans++;
				f=1;
			}
		}else if(c[i].a<0){
			t=p[lower_bound(p+1,p+m+1,c[i].s)-p];
			vf=sv(c[i].v,c[i].a,t-c[i].s);
			if(vf>v*v){
				ans++;
				ff++;
			}
		}else{
			ve=sv(c[i].v,c[i].a,p[m]-c[i].s);
			if(ve>v*v){
				ans++;
				f=1;
			}
		}
	}
	cout<<ans<<' ';
	return ans;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	ios::sync_with_stdio(0);
	int T/*,cnt=0*/;
	cin>>T;
	while(T--){
	//	cnt++;
//		if(cnt!=10)continue;
		f=0;
		ff=0;
		cin>>n>>m>>L>>v;
		for(int i=1;i<=n;i++){
			cin>>c[i].s>>c[i].v>>c[i].a;
			//if(c[i].a<0)ff++;
		}
		for(int i=1;i<=m;i++){
			cin>>p[i];
		}
		if(test()==0){
			cout<<m<<endl;
			continue;
		}
		if(ff){
			if(ff==1){
				if(f)cout<<m-2<<endl;
				else cout<<m-1<<endl;
			}else{
				if(f)cout<<m-ff<<endl;
				else cout<<m-ff+1<<endl;
			}
		}else{
			if(f)cout<<m-1<<endl;
			else cout<<m<<endl;
		}
	}
	return 0;
}
